package com.mori.openfeign;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>  </p>
 *
 * @author mori
 * @since 10/17/2019 2:46 PM
 */
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class OpenFeignApplication {

    public static void main(String[] args) {
        SpringApplication.run(OpenFeignApplication.class, args);
    }

    @Slf4j
    @RestController
    static class TestController {
       private Client client;

        public TestController(Client client) {
            this.client = client;
        }

        @GetMapping("/test")
        public String test() {
            String result = client.hello("nacos");
            return "Return : " + result;
        }
    }


    @FeignClient("nacos-discovery-server")
    interface Client {
        /**
         * hello
         *
         * @param name
         * @return
         */
        @GetMapping("/hello")
        String hello(@RequestParam(name = "name") String name);
    }

}
